package seven.test_7_7;

import java.util.ArrayList;
import java.util.HashSet;

public class Solution {
    public ArrayList<Integer> intersection (ArrayList<Integer> nums1, ArrayList<Integer> nums2) {
        // write code here
        HashSet<Integer> set = new HashSet<>();
        HashSet<Integer> hashSet = new HashSet<>();
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int i = 0; i < nums1.size(); i++) {
            hashSet.add(nums1.get(i));
        }
        for (int i = 0; i < nums2.size(); i++) {
            if(hashSet.contains(nums2.get(i))) {
                set.add(nums2.get(i));
            }
        }
        for (int i : set) {
           arrayList.add(i);
        }
        return arrayList;
    }
}
